package com.wonderful.wedding.model;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.json.JSONObject;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;


//@Data
//@NoArgsConstructor
@SuppressWarnings("unchecked")
public class MyCloudResult {
    private int code;
    private JSONObject data;
    private String message;

    public MyCloudResult() {
    }

    public MyCloudResult(int code, JSONObject data, String message) {
        this.code = code;
        this.data = data;
        this.message = message;
    }

    public MyCloudResult(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public static ResponseEntity parseToEntity(MyCloudResult myCloudResult) {
        //-1302 个体已存在
        if (myCloudResult.getCode() == 0 || myCloudResult.getCode() == -1302) {
            return new ResponseEntity(myCloudResult.getMessage(), HttpStatus.OK);
        } else {
            return new ResponseEntity(myCloudResult.getMessage(), HttpStatus.BAD_REQUEST);
        }

    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public JSONObject getData() {
        return data;
    }

    public void setData(JSONObject data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
